package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.adapter.part.MsgContentAdapter;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.bean.MsgContentBean;
import com.yanchangapp.util.CommonHelper;
import com.zxl.baselib.util.time.TimeUtil;

import java.util.List;

/**
 * Created by apple on 2019-10-25.
 * description:
 */
public class NMsgContentAdapter extends BaseQuickAdapter<MsgContentBean, BaseViewHolder> {
    private boolean isEdit = false;


    public void setEditState(boolean isEdit){
        this.isEdit = isEdit;
    }

    public NMsgContentAdapter( @Nullable List<MsgContentBean> data) {
        super(R.layout.item_msg_content, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MsgContentBean item) {
        RelativeLayout rlEditStyle = helper.getView(R.id.rlEditStyle);
        View rlLookStyle = helper.getView(R.id.rlLookStyle);
        TextView tvMsgCnt = helper.getView(R.id.tvMsgContent);
        TextView tvMsgData = helper.getView(R.id.tvMsgTime);
        CheckBox checkBox = helper.getView(R.id.checkbox);
        TextView tvName = helper.getView(R.id.tvTextSingleName);

        if (TextUtils.isEmpty(item.getName())){
            tvName.setTextSize(12);
        }else {
            tvName.setTextSize(15);
        }
        tvName.setText(CommonHelper.getSingleName(item.getName()));

        boolean hadRead = item.getMsgReadStatus() != AppConstant.MSG_UN_READ;

        if (this.isEdit){
            rlEditStyle.setVisibility(View.VISIBLE);
            rlLookStyle.setVisibility(View.GONE);
        }else {
            rlEditStyle.setVisibility(View.GONE);
            rlLookStyle.setVisibility(View.VISIBLE);
        }
        // 设置已读未读的
        rlLookStyle.setSelected(hadRead);
        tvMsgCnt.setSelected(hadRead);
        tvMsgCnt.setText(item.getMsgContent());
        tvMsgData.setText(TimeUtil.getTimeDes(item.getCreateTime()));
        // 设置默认为未选中

//        holder.checkBox.setChecked(false);
//        holder.checkBox.setOnCheckedChangeListener(new MsgContentAdapter.MyCheckChangeListener(holder.getAdapterPosition()));
//        holder.itemView.setOnClickListener(new MsgContentAdapter.ItemClickListener(holder.getAdapterPosition(),msgContentBean,holder.checkBox));


    }
}
